//---------------------------------------------------------------------
// Author: Keith Hill, jachymko
//
// Description: Base class for all commands which need an Encoding parameter
//
// Creation Date: Dec 9, 2006
//---------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Text;
using System.Management.Automation;

namespace Pscx.Commands.Internal
{
    public abstract class PscxEncodingCommandBase : PscxPathCommandBase
    {
        private Encoding _defaultEncoding = System.Text.Encoding.UTF8;
        private EncodingParameter _encoding;

        [Parameter(ValueFromPipelineByPropertyName = true,
                   HelpMessage = "The encoding to use for this operation.  Valid values are: ASCII, UTF7, UTF8, UTF32, Unicode, BigEndianUnicode and Default.")]
        [AcceptsWildcards(false)]
        [ValidateNotNullOrEmpty]
        [ValidateSet("ascii", "utf7", "utf8", "utf32", "unicode", "bigendianunicode", "default")]
        public EncodingParameter Encoding
        {
            get { return _encoding; }
            set { _encoding = value; }
        }

        protected Encoding DefaultEncoding
        {
            get { return _defaultEncoding; }
            set { _defaultEncoding = value; }
        }

        protected Encoding GetEncoding()
        {
            return (_encoding.IsPresent ? _encoding.ToEncoding() : _defaultEncoding);
        }
    }
}
